-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update TemporaryFolder.newFolder(String) to support passing in paths #1402
Update TemporaryFolder.newFolder(String) to support passing in paths #1402
Conversation
if (folder.startsWith(File.separator)) { | ||
throw new IOException("Folder name cannot start with a file separator"); | ||
} | ||
return newFolder(folder.split(FILE_SEPARATOR_REGEX)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the regex, can we use new File(folder)
and call getParent()
until it returns null
? This way a test could use newFolder("foo/bar")
and be able to run on Windows and Unix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize that File supported / as a path separator for Windows.
Instead of your solution, how about I rewite this method to use mkdirs()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you report already existing intermediate folders (see newFolder(String[])
) that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newFolder(String...)
does not report already existing intermediate directories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the code it looks like it does… 😯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind... 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use mkdirs() and added a test for paths that contain a forward slash and for paths that contain the file separator.
tempFolder.newFolder("temp1/temp2"); | ||
File temp1 = new File(tempFolder.getRoot(), "temp1"); | ||
assertFileIsDirectory(temp1); | ||
assertFileIsDirectory(new File(temp1, "temp2")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test won't run on Windows, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
BTW, the behavior changes in 4.12 broke some of our tests. When I am back in the office tomorrow I will verify that this change resolves the problems. |
370cae0
to
b94b56e
Compare
PTAL. Thanks, @marcphilipp ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…ashes. In JUnit 4.11, newFolder(String) was changed to no longer support paths with a file separator. This has been fixed. The overload of newFolder() that supports passing in multiple strings still does not allow strings containing file separators.
b94b56e
to
c47bb64
Compare
I verified that this is a regression from the behavior in JUnit 4.11 and changed the commit comment accordingly. I also removed the use of Any objections to merging this? Note I'm also considering changing newFolder(String...) to support paths with slashes, since the inconsistency is weird and supporting slashes would be consistent with |
@@ -167,16 +167,27 @@ public File newFile() throws IOException { | |||
} | |||
|
|||
/** | |||
* Returns a new fresh folder with the given name under the temporary | |||
* Returns a new fresh folder with the given path under the temporary | |||
* folder. | |||
*/ | |||
public File newFolder(String folder) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably rename folder
to path
, right?
File file = new File(getRoot(), folder); | ||
if (!file.mkdirs()) { | ||
throw new IOException( | ||
"a folder with the name \'" + folder + "\' already exists"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this error message really accurate? I know it's the same as in the other method but I'm sure there are other reasons why a folder could not be created.
👍
None at all.
I think supporting slashes is great! I've tried to find out why it was implemented that way. From #946 it seems 4.10 used only |
Please add a description of this improvement to the draft of the release notes. |
@marcphilipp I updated the release notes. Sorry, I somehow didn't see some of your comments. I'll address them soon. |
Thanks! And no worries about those comments. 🙂 |
…ashes. (junit-team#1402) In JUnit 4.11, newFolder(String) was changed to no longer support paths with a file separator. This has been fixed. The overload of newFolder() that supports passing in multiple strings still does not allow strings containing file separators.
…ashes. (junit-team#1402) In JUnit 4.11, newFolder(String) was changed to no longer support paths with a file separator. This has been fixed. The overload of newFolder() that supports passing in multiple strings still does not allow strings containing file separators.
that include path separator characters. The overload of newFolder() that
supports passing in multiple strings still does not allow path separators.